import { reqBanner } from "../../http/api";

// 1.初始值
const initState = {
    //初始轮播图
    banner: []
}

// types
const types = {
    MINE_CHANGE_BANNER: "MINE_CHANGE_BANNER"
}
// reducer
export const mineReducer = (state = initState, action) => {
    switch (action.type) {
        case types.MINE_CHANGE_BANNER:
            return {
                ...state,
                banner: action.banner
            }
            break;
        default:
            return state
    }
}
// actions
export const actions = {
    changeBanner: banner => ({ type: types.MINE_CHANGE_BANNER, banner }),
    // 发请求
    reqBannerAction: () => {
        return (dispatch, getState) => {
            // 发请求
            reqBanner().then(res => {
                if (res.data.code === 200) {
                    dispatch(actions.changeBanner(res.data.list))
                }
            })
        }
    }
}


// 导出数据
export const getBanner = state => state.mine.banner